/*
 * semantics.c
 *
 *  Created on: Oct 2, 2008
 *      Author: V
 */

#include "semantics.h"
#include <string.h>
#include <assert.h>

int semanticsInit()
{
	return LookupTableInit();
}

pAnonymousStatement anonymousStatementFunction(
		char* operation,
		ArgumentList arguments)
{
	//printf("#anonymous statement: %s\n", operation);
	pAnonymousStatement ret = AnonymousStatement_new();
	ret->operator = String_new(operation);
	ret->argumentList = arguments;
	return ret;
}

void labeledStatementFunction(char* label, pAnonymousStatement statement)
{
	// table init'd, statement constructed
	// just need to add to table
	assert(label != NULL);
	assert(statement != NULL);
	if (table == NULL)
	{
		table = LookupTable_new();
	}
	assert(table != NULL);
	table->add(table, String_new(label), statement);

	/*printf("#labeled statement: %s:%s\n",
			label,
			statement->toString(statement)->cString);
	*/
}

ArgumentList argumentsFunction(int argumentLength, pArgument argument, ...)
{
	ArgumentList ret = (ArgumentList)
		GC_malloc(sizeof(pArgument)*(argumentLength+1));
	ret[0] = argument;
	va_list list;
	va_start(list, argument);

	int i;
	for (i = 1; i < argumentLength; i++)
	{
		ret[i] = va_arg(list, pArgument);
	}

	ret[i] = NULL;
	va_end(list);
	//printf("!argumentsFunction Result: %s\n", ArgumentList_toString(ret)->cString);
	return ret;
}
